package com.ybu.controller;

import com.ybu.common.Constants;
import com.ybu.common.JwtUtils;
import com.ybu.common.R;
import com.ybu.pojo.vo.UserLoginVO;
import com.ybu.service.DeletFavoriteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
@RequestMapping("api/favorite")
@Slf4j
public class DeletFavoriteController {
    /**
     *
     */
    @Autowired
    private DeletFavoriteService deletFavoriteService;

    @DeleteMapping("delete/{productId}")
    public R<Void> delete(@PathVariable Integer productId, HttpServletRequest request) {
        log.debug("product:{}",productId);
        String token = request.getHeader(Constants.TOKEN_HEADER);
        UserLoginVO userLoginVO = JwtUtils.parseToken(token);
        deletFavoriteService.delet(productId,userLoginVO);
        return R.ok();
    }
}
